What is lazy-cache?
The lazy-cache npm package is designed to lazily require modules, meaning that the modules are only required when they are actually needed. This can help improve the performance of your application by deferring the loading of modules until they are used.
What are lazy-cache's main functionalities?
Lazy Loading of Modules
This feature allows you to defer the loading of a module until it is actually used in your code. In the example, the 'fs' module is not loaded until the 'readFileSync' method is called.
const lazy = require('lazy-cache')(require);
const fs = lazy('fs');
// fs is not loaded until it is used
fs.readFileSync('path/to/file.txt', 'utf8');
Custom Lazy Loading
You can also use lazy-cache to lazily load your own custom modules. In this example, the './customModule' is not loaded until 'someFunction' is called.
const lazy = require('lazy-cache')(require);
const customModule = lazy('./customModule');
// customModule is not loaded until it is used
customModule.someFunction();
Other packages similar to lazy-cache
require-lazy
The require-lazy package provides similar functionality by allowing you to lazily require modules. It offers a simple API for deferring the loading of modules until they are needed, similar to lazy-cache.
proxyquire
Proxyquire is a powerful tool for mocking dependencies during testing, but it also supports lazy loading of modules. It allows you to mock out dependencies and control when they are loaded, providing more flexibility compared to lazy-cache.
import-lazy
Import-lazy is another package that allows you to lazily import modules. It uses ES6 proxies to defer the loading of modules until they are accessed, offering a modern alternative to lazy-cache.
lazy-cache
Cache requires to be lazy-loaded when needed.
Install
Install with npm
$ npm i lazy-cache --save
Usage
var lazyCache = require('lazy-cache');
var glob = lazyCache(require)('glob');
glob().sync('foo/*.js');
Running tests
Install dev dependencies:
$ npm i -d && npm test
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Author
Jon Schlinkert
License
Copyright © 2015 Jon Schlinkert
Released under the MIT license.
This file was generated by verb-cli on June 01, 2015.